package graphics;

import java.awt.Color;
import java.awt.Graphics2D;

import physics.Coordinate;
import physics.Obstacle;
import physics.Vector;
import physics.World;
import platform.TileBlock;

public class WorldDrawer {

	public static double FORCE_SCALING = 0.25; // The forces drawn will be multiplied by this number.
	public static boolean DRAW_VECTORS = false;
	
	
	public static void drawWorld(Graphics2D g, World world){
		
		
		for (Obstacle o : world.getObstacles())
			drawObstacle(g, o);
		
	}

	private static void drawObstacle(Graphics2D g, Obstacle o) {
		
		g.setColor(Color.BLACK);
		g.draw(o.getShape());
		if(o instanceof TileBlock){
			
			g.draw(o.getShape().getBounds());
		}
		if (DRAW_VECTORS)
			drawVector(g, o.getVector(), o.getLocation());
	}
	
	private static void drawVector(Graphics2D g, Vector v,Coordinate position){
		drawLine(g, position, v.getAngle(), (v.getForce() * FORCE_SCALING));
		double xEnd = (position.x + (v.getxForce() * FORCE_SCALING));
		double yEnd = (position.y + (v.getyForce() * FORCE_SCALING));
		drawLine(g, new Coordinate(xEnd, yEnd), v.getAngle() + Math.toRadians(75 + (Math.signum(v.getForce()) * 90)), 10);
		drawLine(g, new Coordinate(xEnd, yEnd), v.getAngle() + Math.toRadians(-75 - (Math.signum(v.getForce()) * 90)), 10);
	}
	
	
	private static void drawLine(Graphics2D g, Coordinate position,double angle, double length)
	{
		Vector v = new Vector(angle, length);
		int xEnd = (int) (position.x + v.getxForce());
		int yEnd = (int) (position.y + v.getyForce());
		g.drawLine((int) position.x,(int) position.y, xEnd, yEnd);
	}
}
